package com.crx.springbootinit.controller.admin;

import com.crx.springbootinit.annotation.AuthCheck;
import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.dto.post.PostPageDTO;
import com.crx.springbootinit.model.vo.post.PostPageVO;
import com.crx.springbootinit.model.vo.post.PostVO;
import com.crx.springbootinit.service.IPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 谢杭延
 * @Date 2024-11-01 13:00
 */
@RestController
@RequestMapping("/admin/post")
@RequiredArgsConstructor
@Api(tags = "后台帖子模块接口")
public class PostAdminController {
    private final IPostService postService;
    @ApiOperation("分页查询帖子列表")
    @GetMapping("/page")
    @LogApiAnno(title = "帖子模块", businessType = "GET")
    @AuthCheck
    public BaseResponse<PageVO<PostPageVO>> queryPostPage(PostPageDTO postPageDTO){
        PageVO<PostPageVO> pageVO =postService.queryPostPage(postPageDTO);
        return BaseResponse.success(pageVO);
    }

    @ApiOperation("删除帖子列表")
    @DeleteMapping("/delete/{ids}")
    @LogApiAnno(title = "帖子模块", businessType = "DELETE")
    @AuthCheck
    public BaseResponse deletePost(@ApiParam("帖子id列表") @PathVariable List<Long> ids){
        postService.deletePost(ids);
        return BaseResponse.success();
    }

    @GetMapping("/getPostById")
    @ApiOperation("获取帖子详情")
    @LogApiAnno(title = "帖子模块", businessType = "GET")
    public BaseResponse<PostVO> getPostById(HttpServletRequest request, @RequestParam Long postId) {
        String token = request.getHeader("token");
        PostVO postVO = postService.getPostById(token,postId);
        return BaseResponse.success(postVO);
    }
}
